using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CodeStory.Core.UI;
using CodeStory.Core.Attributes;
using CodeStory.WebControls;
using CodeStory.Core.ObjectEntity;
using Activa.CoolStorage;

namespace CodeStory.WebApplication.Modules.Core
{
	public partial class Note : Portlet
	{
		protected override void OnInit(EventArgs e) {
			Load += new EventHandler(Note_Load);
			base.OnInit(e);
		}

		void Note_Load(object sender, EventArgs e) {
			//throw new Exception("The method or operation is not implemented.");
			if (!IsPostBack) {
				BindNote();
			}
		}

		private void BindNote() {
			NoteObject note = null;
			try {
				note = NoteObject.Read(NoteID);
			} catch {
			}
			if (note == null) {
				lblNote.Text = "Please select note";
				return;
			}
			lblNote.Text = note.NoteContent;
			Title = note.NoteTitle;
		}

		[PortletSetting]
		[PropertyEditor(typeof(NoteEditor))]
		public Guid NoteID {
			get { 
				object obj = Setting["NoteID"];
				return obj == null ? Guid.Empty : (Guid)obj;
			}
			set { Setting["NoteID"] = value; }
		}
	}

	public class NoteEditor : DropDownPropertyEditor
	{
		public override void Prepare() {
			//base.Prepare();
			CSList<NoteObject> list = NoteObject.List();
			Items.Clear();
			foreach (NoteObject obj in list) {
				ListItem item = new ListItem(obj.NoteTitle,obj.NoteID.ToString());
				Items.Add(item);
			}
		}
	}
}